/*
 * Copyright 2022,2023 NXP.
 *
 * NXP Confidential. This software is owned or controlled by NXP and may only be
 * used strictly in accordance with the applicable license terms. By expressly
 * accepting such terms or by downloading,installing, activating and/or otherwise
 * using the software, you are agreeing that you have read,and that you agree to
 * comply with and are bound by, such license terms. If you do not agree to be
 * bound by the applicable license terms, then you may not retain, install, activate
 * or otherwise use the software.
 *
 */

#ifndef UWBRADAR_BD_H
#define UWBRADAR_BD_H

#include "uwbradar_common.h"
#include <stdlib.h>
#include <stdbool.h>

#if defined(__GNUC__)
#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
#elif defined(_MSC_VER)
#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
#endif

/** \addtogroup uwbradar_apis
 *
 * @{ */

/**
 * @brief  Enumeration lists out the Breathing callback object detection types.
*/
typedef enum _bd_object_detection
{
    /** Critical error occurred */
    kBD_CbObjectTypeError = 0,
    /** No presence detected */
    kBD_CbObjectTypeNoPresence,
    /** Not sure, whether person is present – unreliable */
    kBD_CbObjectTypeUnreliable,
    /** Low accuracy detection of location and breathing */
    kBD_CbObjectTypeAccuracyLow,
    /** Medium accuracy detection of location and breathing */
    kBD_CbObjectTypeAccuracyMedium,
    /** High accuracy detection of location and breathing */
    kBD_CbObjectTypeAccuracyHigh,
} bd_object_detection_t;


/**
 * @brief  Structure lists out Breathing Detection callback information.
*/

PACK(struct _bd_Measurement_callback {
    /** Breathing rate in breath per minute */
    float breathing_rate;
    /** Distance to breather in centimeter */
    float breathing_distance;
    /** possible detected object types */
    bd_object_detection_t bd_object_type;
    /** Breathing pattern consisting of new sample CIR receive */
    float *breathing_pattern;
    /** Size of the breathing_pattern */
    uint8_t breathing_pattern_length;
});

typedef struct _bd_Measurement_callback bd_Measurement_callback_t;

/**
 * @brief callback support for Breathing Detection which calls from the internal Radar Lib.
 * \param pBdInfo Pointer to bd_Measurement_callback_t struct, contains the breathing related params .
*/
typedef void (*UwbRadarApi_Breathing_Measurement_Callback_t)(bd_Measurement_callback_t *pBdInfo);


/**
 * @brief  API to set Breathing Detection configuration for Radar Lib.
 *         API takes breathing configurations and callback as input. The callback can be used to Notifies the result via callback.
 *
 * \param[in]  breathing_update_rate the interval at which the pBdCback will be called and it is a multiple of the RFRI.
 * \param[in]  radar_frame_repeat_interval Radar Frame Repetition Interval in milliseconds can be 100, 50, 20, 10
 *             eg if RFRI=100  and breathing_update_rate=10 then p_cback is called every second
 * \param[in]  pBdCback pBdCback the callback to Notify the Results.

 * \retval  #kStatus_Success    If all params are valid.
 * \retval  #kStatus_Fail       In case RFRI is not one of the allowed values.
 * \retval  #kStatus_Invalid    If breathing_update_rate param less than or equal to  0 and callback is NULL.
*/
uint8_t UwbRadarApi_SetBreathingConfigs(
    uint8_t breathing_update_rate, uint8_t radar_frame_repeat_interval, UwbRadarApi_Breathing_Measurement_Callback_t *pBdCback);

/** @} */ /* @addtogroup uwbradar_apis */
#endif //UWBRADAR_BD_H